package com.mingqi.enetconnected.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by li on 2018/8/20.
 * WeChat 18571658038
 * author LiWei
 */

public class VerifySeekBar extends android.support.v7.widget.AppCompatSeekBar {

    /**
     * 滑块的默认宽度
     */
    private int thumbWidth = 150;
    private int defaultSpace = 20;
    private boolean isCall = true;

    public void setComplete(boolean complete) {
        isComplete = complete;
    }

    private boolean isComplete = false;

    public VerifySeekBar(Context context) {
        this(context,null);
    }

    public VerifySeekBar(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public VerifySeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {

        if(isComplete) {

            return true;
        }

        //基于该view的坐标系的x坐标
        int x = (int) event.getX();
        if (event.getAction() == MotionEvent.ACTION_DOWN){
            isCall = true;
            if (x - thumbWidth > defaultSpace) {
                isCall = false;
                return true;
            }
        }
        if (event.getAction() == MotionEvent.ACTION_MOVE){
            if (!isCall){
                return true;
            }
        }

        return super.dispatchTouchEvent(event);
    }
}
